package com.example.demo.service.impl;

import com.example.demo.mapper.UserManagementMapper;
import com.example.demo.pojo.User;
import com.example.demo.service.UserManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserManagementServiceImpl implements UserManagementService {

    @Autowired
    private UserManagementMapper userManagementMapper;

    public Map<String, Object> getUsers(int current, int size, String nickname) {
        int offset = (current - 1) * size;
        List<User> users = userManagementMapper.findUsers(offset, size, nickname);
        int total = userManagementMapper.countUsers(nickname);

        Map<String, Object> result = new HashMap<>();
        result.put("records", users);
        result.put("current", current);
        result.put("size", size);
        result.put("total", total);

        return result;
    }

    public int addUser(User user) {
        return userManagementMapper.addUser(user);
    }

    public int deleteUser(Long id) {
        return userManagementMapper.deleteUser(id);
    }

    @Override
    public List<User> selectUser(String nickname) {
        return userManagementMapper.selectUser(nickname);
    }

    public int updateUser(User user) {
        return userManagementMapper.updateUser(user);
    }


}
